package ar.edu.utn.frba.gdaia.src.swing.gui;

import java.io.File;

import javax.swing.filechooser.*;

public class ImageFilter extends FileFilter {
    static final String jpeg = "jpeg";
    static final String jpg = "jpg";
    static final String gif = "gif";

    // Accept all directories and all gif, jpg files.

    public boolean accept(File f) {

        if (f.isDirectory()) {
            return true;
        }

        String s = f.getName();
        int i = s.lastIndexOf('.');

        if (i > 0 && i < s.length() - 1) {
            String extension = s.substring(i + 1).toLowerCase();
            if (gif.equals(extension) || jpeg.equals(extension) || 
                jpg.equals(extension)) {
                return true;
            } else {
                return false;
            }
        }

        return false;
    }

    // The description of this filter

    public String getDescription() {
        return "Archivos JPEG, JPG, GIF";
    }
}

